package com.easy.mq.service.impl;

import com.easy.common.component.ExchangeType;
import com.easy.common.service.IMQService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DubboService
public class MQService implements IMQService {
    @Autowired
    RabbitTemplate rabbitTemplate;
    private static final String DEFAULT_EXCHANGE = "topicExchange";
    private static final String DEFAULT_ROUTING_KEY = "Car.order";
    @Override
    public void sendMessage(String message) {
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, DEFAULT_ROUTING_KEY, message);
    }

    @Override
    public void sendMessage(String message, String routingKey) {
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, routingKey, message);
    }

    @Override
    public void sendMessage(String message, String routingKey, ExchangeType exchange) {
        rabbitTemplate.convertAndSend(exchange.toString(), routingKey, message);

    }
}
